//
//  MainViewController.m
//  团购
//
//  Created by 樊荣海 on 15/1/20.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "MainViewController.h"



@interface MainViewController () <DockViewDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = globalBgColor;
    NSLog(@"frame: %@", NSStringFromCGRect(self.view.frame));
    
    
    //1.左侧选项卡
    DockView *dock = [[DockView alloc] init];
    dock.delegate = self;
    dock.frame = CGRectMake(0, 0, 0, self.view.frame.size.height);
    [self.view addSubview:dock];
    
    //2.子控制器
    [self addChildViewControllers];
    

}

- (void)addChildViewControllers {

    DealViewController *deal = [[DealViewController alloc] init];
    BaseNavigationController *dealNavi =  [[BaseNavigationController alloc] initWithRootViewController:deal];
    [self addChildViewController:dealNavi];
    
    MapViewController *map = [[MapViewController alloc] init];
    BaseNavigationController *mapNavi =  [[BaseNavigationController alloc] initWithRootViewController:map];
    [self addChildViewController:mapNavi];
    
    CollectViewController *collect = [[CollectViewController alloc] init];
    BaseNavigationController *collectNavi =  [[BaseNavigationController alloc] initWithRootViewController:collect];
    [self addChildViewController:collectNavi];
    
    MineViewController *mine = [[MineViewController alloc] init];
    BaseNavigationController *mineNavi =  [[BaseNavigationController alloc] initWithRootViewController:mine];
    [self addChildViewController:mineNavi];
    
    [self dockView:nil selectedFrom:0 to:0];
    
}

- (void)dockView:(DockView *)dockView selectedFrom:(NSInteger)from to:(NSInteger)to {

    NSLog(@"from:%ld,  to:%ld",  from, to);
    
    NSLog(@"sb frame: %@", NSStringFromCGRect(self.view.frame));

    UIViewController *fromVC = self.childViewControllers[from];
    UIViewController *toVC = self.childViewControllers[to];
    
    [fromVC.view removeFromSuperview];

    toVC.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    toVC.view.frame = CGRectMake(DockItemW, 0, self.view.frame.size.width-DockItemW, self.view.frame.size.height);
    
    [self.view addSubview:toVC.view];
    
}




@end
